package com.enzo.prms.common.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

/**
 * @author prms1.0
 * 
 * @date:2012-5-2 ����04:47:20
 * @version :
 * 
 */
public class TestTagWithBody extends BodyTagSupport {
	private static final long serialVersionUID = 9024912108075838867L;
	private int count;
	private JspWriter out;

	public void inti() {
//		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		out = pageContext.getOut();
	}

	@Override
	public int doStartTag() throws JspException {
		inti();
		return EVAL_BODY_INCLUDE;
	}

	// ���õ�ǰ��ǩ��
	@Override
	public void setBodyContent(BodyContent bodyContent) {
		this.bodyContent = bodyContent;
	}

	// ��Ҫ��ʼ��bodyContent
	@Override
	public void doInitBody() throws JspException {
		// TODO Auto-generated method stub
		super.doInitBody();
	}

	@Override
	public int doAfterBody() throws JspException {
		if (count >= 1) {
			try {
				out.println(count);
				out.println("<br>");
			} catch (IOException e) {
				e.printStackTrace();
			}
			count--;
			return EVAL_BODY_AGAIN;
		}else{
			return SKIP_BODY;
		}
	}

	@Override
	public int doEndTag() throws JspException {
		try {
			out.println("tag end");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public void setCount(int count) {
		this.count = count;
	}
	
	
	
	

}
